//
//  StoreViewModel.m
//  JiZhuiAn
//
//  Created by Easy.Lin on 16/6/19.
//  Copyright © 2016年 Easy. All rights reserved.
//

#import "StoreViewModel.h"
#import "APIService+Store.h"

@interface StoreViewModel ()

@property (nonatomic, strong) RACCommand * searchCommand;
@property (nonatomic, strong) LoadingRACCommand * goodPercent_sortCommand;
@property (nonatomic, strong) LoadingRACCommand * salesNumber_sortCommand;
@property (nonatomic, strong) LoadingRACCommand * salesPrice_sortCommand;

@end

@implementation StoreViewModel

- (void)initialize
{
    @weakify(self);
    self.searchCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(NSString * input) {
        return [[[APIService shareService] searchCommodityWithKeyWord:input] doNext:^(id x) {
            @strongify(self);
            self.dataSource = x;
        }];
    }];
    self.goodPercent_sortCommand = [[LoadingRACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
        return [[[APIService shareService] getCommodityWithSortType:@"rateOfPraise"] doNext:^(NSArray * x) {
            @strongify(self);
            self.dataSource = x;
        }];
    }];
    self.salesNumber_sortCommand = [[LoadingRACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
        return [[[APIService shareService] getCommodityWithSortType:@"salesNumber"] doNext:^(NSArray * x) {
            @strongify(self);
            self.dataSource = x;
        }];
    }];
    self.salesPrice_sortCommand = [[LoadingRACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
        return [[[APIService shareService] getCommodityWithSortType:@"price"] doNext:^(NSArray * x) {
            @strongify(self);
            self.dataSource = x;
        }];
    }];
}

- (RACSignal *)didSelectedSignalWithIndexPath:(NSIndexPath *)indexPath
{
    return [RACSignal empty];
}

@end
